package com.swak.loadbalance;

import com.swak.loadbalance.impl.LeastActiveLoadBalance;
import com.swak.loadbalance.impl.RandomLoadBalance;
import com.swak.loadbalance.impl.RoundRobinLoadBalance;
import com.swak.loadbalance.impl.WeightingLeastActiveLoadBalance;
import com.swak.loadbalance.impl.WeightingRandomLoadBalance;
import com.swak.loadbalance.impl.WeightingRoundRobinLoadBalance;

/**
 * 负载均衡的方式
 * 
 * @author lifeng
 * @date 2021年3月2日 下午5:16:54
 */
public enum LoadBalances {

	/**
	 * 使用数
	 */
	LeastActive,

	/**
	 * 随机
	 */
	RandomLoad,

	/**
	 * 轮询
	 */
	RoundRobin,

	/**
	 * 一致性hash
	 */
	ConsistentHash,

	/**
	 * 加权使用数
	 */
	WeightingLeastActive,

	/**
	 * 加权随机
	 */
	WeightingRandom,

	/**
	 * 加权轮询
	 */
	WeightingRoundRobin;

	public <T> LoadBalance<T> newLoadBalance() {
		if (this == LeastActive) {
			return new LeastActiveLoadBalance<T>();
		} else if (this == RandomLoad) {
			return new RandomLoadBalance<T>();
		} else if (this == RoundRobin) {
			return new RoundRobinLoadBalance<T>();
		} else if (this == WeightingLeastActive) {
			return new WeightingLeastActiveLoadBalance<T>();
		} else if (this == WeightingRandom) {
			return new WeightingRandomLoadBalance<T>();
		} else if (this == WeightingRoundRobin) {
			return new WeightingRoundRobinLoadBalance<T>();
		}
		return null;
	}
}
